package com.pengliu.config.security;

import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import com.pengliu.util.Constants;
import com.pengliu.util.SysConfig;

/**
 * user: pengliu
 * date: 2017年9月28日
 * desc: 验证码判断
 */
public class SecurityLoginParams extends WebAuthenticationDetails {
	
	//是否开启验证码功能
	@Value("${isOpenValidateCode}")
	private boolean isOpenValidateCode;
	//页面传过来的验证码
	private String validateCode;
	//Session里面的验证码
	private String sessionCode;
	
	public String getValidateCode() {
		return validateCode;
	}
	public String getSessionCode() {
		return sessionCode;
	}
	public boolean isOpenValidateCode() {
		return isOpenValidateCode;
	}
	public SecurityLoginParams(HttpServletRequest request) {
		
		super(request);
		
		if(isOpenValidateCode) {
			validateCode = (String) ObjectUtils.defaultIfNull(request.getParameter("validateCode"), "");
			sessionCode = (String) ObjectUtils.defaultIfNull(request.getSession().getAttribute(Constants.SESSION_SECURITY_CODE), "");
			//释放Session中的验证码
			request.getSession().removeAttribute(Constants.SESSION_SECURITY_CODE);
		}
	}
}
